import { createAPI } from '@/utils/request'
import moment from 'moment';
// 查询企业的部门列表、
var changeState = new Map([
  ['1', '单选'],
  ['2', '多选'],
  ['3', '简答']

])
var changeDifficulty = new Map([
  ['1', '简单'],
  ['2', '一般'],
  ['3', '困难']

])

export const getbasicsTestList = params => createAPI('/questions', 'get', params)


// 这个项目之前的写法要更正
// export function getCompanysList() {
//   return createAPI({
//     url: '/companys',
//     method: 'get',
//     // params: {
//     //   page: 1,
//     //   pagesize: 10,
//     // },
//   })
   // 处理成功
  //  .then(res => console.log(res.data))
    // .then(res => res.data)
    .then(res => ({

      counts:res.data.counts,
      items: res.data.items.map((d,i)=>({
        ...d,
        difficulty: changeDifficulty.get(d.difficulty),
        questionType: changeState.get(d.questionType),
        addDate: moment(d.addDate).format('YYYY-MM-DD H:mm:ss'),
        // question: `<div v-html="${d.question}"></div>`
      //   <div class="laststylte" v-html="'【答案解析】:'+ LookOverList.answer" >
      //   <!-- {{LookOverList.answer ? `【答案解析】：${LookOverList.answer}  `:'无'}} -->
      // </div>

      }))

    }))

   // 处理错误
   .catch(() => []);
// }




// 学科下拉菜单
export const getSubjectsSimpleList = params => createAPI(`/subjects/simple`, 'get', params)

   // 处理成功
  //  .then(res => console.log('8',res))
    .then(res => res.data)

   // 处理错误
   .catch(() => {});


// 用户简单列表（目前是用在录入人列表）
export const getUsersSimpleList = params => createAPI(`/users/simple`, 'get', params)

   // 处理成功
  //  .then(res => console.log('8',res))
    .then(res => res.data)

   // 处理错误
   .catch(() => {});


// 学科二级目录（新添加）secondLevel
export const getSecondLevelList = params => createAPI(`/directorys/simple`, 'get', params)

   // 处理成功
  //  .then(res => console.log('8',res))
    .then(res => res.data)

   // 处理错误
   .catch(() => {});


// 获取搜索页标签选项数据
export const getTagsSimpleList = params => createAPI(`/tags/simple`, 'get', params)

   // 处理成功
  //  .then(res => console.log('8',res))
    .then(res => res.data)

   // 处理错误
   .catch(() => {});




  // let changeStatea = new Map([
  //   ["1", '单选'],

  // ])


//  基础题库详情 题目预览
export const getLookOverList = params => createAPI(`/questions/${params.id}`, 'get', params)

   // 处理成功
  //  .then(res => console.log('8',res.data))
    .then(res => res.data)
    // .then(res=>({
    //     data:res.data.map((d,i)=>({
    //       ...d,
    //       questionType: questionType.get(d.questionType)

    //     })),

    // }))

     // 处理错误
   .catch(() => {});



//  基础题库删除
export const deletebasicTest = params => createAPI(`/questions/${params.id}`, 'delete', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


//  加入或移出精选 /questions/choice/:id/:choiceState
export const choicenessTest = params => createAPI(`/questions/choice/${params.id}/${params.choiceState}`, 'patch', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});



//  基础题库添加 /questions
export const addTest = data => createAPI(`/questions`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});





var changeState = new Map([
  ['1', '单选'],
  ['2', '多选'],
  ['3', '简答']

])
var changeDifficulty = new Map([
  ['1', '简单'],
  ['2', '一般'],
  ['3', '困难']

])
//  精选题库列表  /questions/choice
export const getChoiceList = params => createAPI(`/questions/choice`, 'get', params)

// 处理成功
//  .then(res => console.log('8',res.data))s
//  .then(res => res.data)
.then(res => ({

  counts:res.data.counts,
  items: res.data.items.map((d,i)=>({
    ...d,
    difficulty: changeDifficulty.get(d.difficulty),
    questionType: changeState.get(d.questionType),
    addDate: moment(d.addDate).format('YYYY-MM-DD H:mm:ss'),
    chkState: d.chkState ? '已审核' : '待审核',
    publishState: d.publishState ? '已下架' : '已发布',

  }))

}))

  // 处理错误
.catch(() => {});



//  精选题库上下架
export const putSold = data => createAPI(`/questions/choice/${data.id}/${data.publishState}`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});


//  试题审核
export const checkTest = data => createAPI(`/questions/check/${data.id}`, 'post', data)

// 处理成功
//  .then(res => console.log('8',res.data))s
 .then(res => res.data)

  // 处理错误
.catch(() => {});
